/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SeriesPropertiesDialog.java
 *
 * Created on 2012-02-26, 20:39:57
 */
package JFreeChartExtensions.ChartPanelDialogs;

import JFreeChartExtensions.chartextensions.crosshair.CrossHairManager;
import JFreeChartExtensions.ExtendableChartPanel;
import java.awt.Color;
import javax.swing.JColorChooser;

/**
 *
 * @author Nobody
 */
public class CrosshairPropertiesDialog extends ChartPanelDialog{

   private CrossHairManager manager;
  
    public CrosshairPropertiesDialog(ExtendableChartPanel panel) {
        super(panel);
        initComponents();
        this.manager = (CrossHairManager) panel.getExtensionByName("CrossHairExtension").getChartExtensionManager();
        extractSeriesPropertiesToUIControls();
    }

    private void extractSeriesPropertiesToUIControls() {
        AttractToPointCheckBox.setSelected(manager.isAttractToPoints());
        EnableRangeMarkerCheckBox.setSelected(manager.isShowRangeMarker());
        EnableDomainMarkerCheckBox.setSelected(manager.isShowDomainMarker());
    }

    private void saveSettings() {
        manager.setAttractToPoints(AttractToPointCheckBox.isSelected());
        manager.setShowRangeMarker(EnableRangeMarkerCheckBox.isSelected());
        manager.setShowDomainMarker(EnableDomainMarkerCheckBox.isSelected());
        manager.update();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        colorChooser = new javax.swing.JColorChooser();
        mainPanel = new javax.swing.JPanel();
        propertiesPanel = new javax.swing.JPanel();
        colorLabel = new javax.swing.JLabel();
        setLineColorButton = new javax.swing.JButton();
        AttractToPointCheckBox = new javax.swing.JCheckBox();
        EnableRangeMarkerCheckBox = new javax.swing.JCheckBox();
        EnableDomainMarkerCheckBox = new javax.swing.JCheckBox();
        setLabelColor = new javax.swing.JButton();
        colorLabel1 = new javax.swing.JLabel();
        SeriesPanel = new javax.swing.JPanel();
        SeriesName = new javax.swing.JLabel();
        ButtonsPanel = new javax.swing.JPanel();
        OkButton = new javax.swing.JButton();
        CancelButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        propertiesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Properties"));

        colorLabel.setText("Marker Color :");

        setLineColorButton.setText("Set Color...");
        setLineColorButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                setLineColorButtonMouseClicked(evt);
            }
        });

        AttractToPointCheckBox.setText("Attract to points");

        EnableRangeMarkerCheckBox.setText("Enable Range marker");

        EnableDomainMarkerCheckBox.setText("Enable Domain marker");

        setLabelColor.setText("Set Color...");
        setLabelColor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                setLabelColorMouseClicked(evt);
            }
        });

        colorLabel1.setText("Label Color :");

        javax.swing.GroupLayout propertiesPanelLayout = new javax.swing.GroupLayout(propertiesPanel);
        propertiesPanel.setLayout(propertiesPanelLayout);
        propertiesPanelLayout.setHorizontalGroup(
            propertiesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(propertiesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(propertiesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(EnableDomainMarkerCheckBox)
                    .addComponent(EnableRangeMarkerCheckBox)
                    .addComponent(AttractToPointCheckBox)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, propertiesPanelLayout.createSequentialGroup()
                        .addComponent(colorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(setLineColorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, propertiesPanelLayout.createSequentialGroup()
                        .addComponent(colorLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(setLabelColor, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        propertiesPanelLayout.setVerticalGroup(
            propertiesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(propertiesPanelLayout.createSequentialGroup()
                .addComponent(AttractToPointCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(EnableRangeMarkerCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(EnableDomainMarkerCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(propertiesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(colorLabel)
                    .addComponent(setLineColorButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(propertiesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(colorLabel1)
                    .addComponent(setLabelColor)))
        );

        SeriesName.setText("Crosshair Properties");
        SeriesPanel.add(SeriesName);

        OkButton.setText("OK");
        OkButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                OkButtonMouseClicked(evt);
            }
        });
        ButtonsPanel.add(OkButton);

        CancelButton.setText("Cancel");
        CancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CancelButtonMouseClicked(evt);
            }
        });
        ButtonsPanel.add(CancelButton);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(SeriesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(propertiesPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ButtonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(SeriesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(propertiesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void setLineColorButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setLineColorButtonMouseClicked
        Color c = manager.getLineColor();
        if ((c = JColorChooser.showDialog(parentPanel, "Choose Color for Line Marker", c)) != null) {
            manager.setLineColor(c);
        }

    }//GEN-LAST:event_setLineColorButtonMouseClicked

    private void CancelButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CancelButtonMouseClicked
        this.dispose();
    }//GEN-LAST:event_CancelButtonMouseClicked

    private void OkButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_OkButtonMouseClicked
        saveSettings();
        this.dispose();
    }//GEN-LAST:event_OkButtonMouseClicked

    private void setLabelColorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_setLabelColorMouseClicked
        Color c = manager.getLabelColor();
        if ((c = JColorChooser.showDialog(parentPanel, "Choose Color for Label Marker", c)) != null) {
            manager.setLabelColor(c);
        }
    }//GEN-LAST:event_setLabelColorMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox AttractToPointCheckBox;
    private javax.swing.JPanel ButtonsPanel;
    private javax.swing.JButton CancelButton;
    private javax.swing.JCheckBox EnableDomainMarkerCheckBox;
    private javax.swing.JCheckBox EnableRangeMarkerCheckBox;
    private javax.swing.JButton OkButton;
    private javax.swing.JLabel SeriesName;
    private javax.swing.JPanel SeriesPanel;
    private javax.swing.JColorChooser colorChooser;
    private javax.swing.JLabel colorLabel;
    private javax.swing.JLabel colorLabel1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JPanel propertiesPanel;
    private javax.swing.JButton setLabelColor;
    private javax.swing.JButton setLineColorButton;
    // End of variables declaration//GEN-END:variables
}
